package com.yeban.test1.preparestatement;

import com.yeban.test1.utils.C3P0ByThreadLocalUtils;
import com.yeban.test1.utils.Test1Utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/11/17
 */
public class ManagerDao {

    public boolean login(String name, String password) {
        Connection conn = C3P0ByThreadLocalUtils.getConn();
        PreparedStatement ppst = null;
        ResultSet rs = null;
        boolean flag;
        try {
            //2.预编译SQL语句，获取语句对象
            String sql = "select * from admin  where name = ? and password=?";
            ppst = conn.prepareStatement(sql);
            ppst.setString(1, name);
            ppst.setString(2, password);
            //3.执行查询操作，获取结果集
            rs = ppst.executeQuery();
            flag = rs.next();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            //5.关闭资源
            C3P0ByThreadLocalUtils.close();
        }
        return flag;
    }

    /*// 通过用户名和密码查询信息是否登录成功
    public boolean login(String username, String password) {
        // Connection conn = Test1Utils.getConn();
        Connection conn = C3P0ByThreadLocalUtils.getConn();
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            String sql = "select * from manager where name = ? and password = ?";
            ps = conn.prepareStatement(sql);
            ps.setString(1, username);
            ps.setString(2, password);
            rs = ps.executeQuery();
            return rs.next();

        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            C3P0ByThreadLocalUtils.close();
        }
    }*/
}
